package com.ruoyi.pcwl.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.pcwl.domain.PcwlShopEnv;
import com.ruoyi.pcwl.domain.query.PcwlShopEnvQuery;
import org.apache.commons.collections4.MapUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.ruoyi.pcwl.mapper.PcwlShopEnvMapper;
import com.ruoyi.pcwl.service.PcwlShopEnvService;


/**
 * 商铺环境信息 业务接口实现
 */
@Service("pcwlShopEnvService")
public class PcwlShopEnvServiceImpl extends ServiceImpl<PcwlShopEnvMapper, PcwlShopEnv> implements PcwlShopEnvService {


	/**
	 * 据条件查询记录数
	 */
	@Override
	public Integer findCountByParam(PcwlShopEnvQuery reqParam) {
		QueryWrapper<PcwlShopEnv> wrapper = new QueryWrapper<>();
		if (reqParam.getId()!=null)
			wrapper.eq("id",reqParam.getId());
		if (reqParam.getShopId()!=null)
			wrapper.eq("shop_id",reqParam.getShopId());
		if (StringUtils.isNotEmpty(reqParam.getTags())) {
			wrapper.like("tags", reqParam.getTags());
		}
		if (reqParam.getHot()!=null)
			wrapper.eq("hot",reqParam.getHot());
		if (reqParam.getMediaFileId()!=null)
			wrapper.eq("media_file_id",reqParam.getMediaFileId());
		if (StringUtils.isNotEmpty(reqParam.getUrl())) {
			wrapper.like("url", reqParam.getUrl());
		}
		if (StringUtils.isNotEmpty(reqParam.getUsername())) {
			wrapper.like("username", reqParam.getUsername());
		}
		if (StringUtils.isNotEmpty(reqParam.getStatus())) {
			wrapper.like("status", reqParam.getStatus());
		}
		if (StringUtils.isNotEmpty(reqParam.getRemark())) {
			wrapper.like("remark", reqParam.getRemark());
		}
		if (MapUtils.isNotEmpty(reqParam.getParams()))
		{
			Map<String, Object> params = reqParam.getParams();
			if (params.keySet().contains("beginTime"))
				wrapper.ge("create_date", params.get("beginTime"));
			if (params.keySet().contains("endTime"))
				wrapper.le("create_date", params.get("endTime"));
		}
		Long aLong = baseMapper.selectCount(wrapper);
		return aLong.intValue();
	}

	/**
	 * 根据条件查询列表
	 */
	@Override
	public IPage<PcwlShopEnv> selectPage(PcwlShopEnvQuery reqParam) {
		QueryWrapper<PcwlShopEnv> wrapper = new QueryWrapper<>();
		if (reqParam.getId()!=null)
			wrapper.eq("id",reqParam.getId());
		if (reqParam.getShopId()!=null)
			wrapper.eq("shop_id",reqParam.getShopId());
		if (StringUtils.isNotEmpty(reqParam.getTags())) {
			wrapper.like("tags", reqParam.getTags());
		}
		if (reqParam.getHot()!=null)
			wrapper.eq("hot",reqParam.getHot());
		if (reqParam.getMediaFileId()!=null)
			wrapper.eq("media_file_id",reqParam.getMediaFileId());
		if (StringUtils.isNotEmpty(reqParam.getUrl())) {
			wrapper.like("url", reqParam.getUrl());
		}
		if (StringUtils.isNotEmpty(reqParam.getUsername())) {
			wrapper.like("username", reqParam.getUsername());
		}
		if (StringUtils.isNotEmpty(reqParam.getStatus())) {
			wrapper.like("status", reqParam.getStatus());
		}
		if (StringUtils.isNotEmpty(reqParam.getRemark())) {
			wrapper.like("remark", reqParam.getRemark());
		}
		if (MapUtils.isNotEmpty(reqParam.getParams()))
		{
			Map<String, Object> params = reqParam.getParams();
			if (params.keySet().contains("beginTime"))
				wrapper.ge("create_date", params.get("beginTime"));
			if (params.keySet().contains("endTime"))
				wrapper.le("create_date", params.get("endTime"));
		}
		return baseMapper.selectPage(reqParam.getPage(), wrapper);
	}

	/**
	 * 新增
	 */
	@Override
	public Integer add(PcwlShopEnv bean) {
		return baseMapper.insert(bean);
	}

	/**
	 * 批量新增
	 */
	@Override
	public Integer addBatch(List<PcwlShopEnv> listBean) {
		if (listBean == null || listBean.isEmpty()) {
			return 0;
		}
		return baseMapper.insertBatch(listBean);
	}

	/**
	 * 批量新增或者修改
	 */
//	@Override
//	public Integer addOrUpdateBatch(List<PcwlShopEnv> listBean) {
//		if (listBean == null || listBean.isEmpty()) {
//			return 0;
//		}
//		return baseMapper.insertOrUpdateBatch(listBean);
//	}

	/**
	 * 多条件更新
	 */
//	@Override
//	public Integer updateByParam(PcwlShopEnv bean, PcwlShopEnvQuery param) {
//		return baseMapper.updateByParam(bean, param);
//	}

	/**
	 * 多条件删除
	 */
//	@Override
//	public Integer deleteByParam(PcwlShopEnvQuery param) {
//		return baseMapper.deleteByParam(param);
//	}

	/**
	 * 根据Id获取对象
	 */
	@Override
	public PcwlShopEnv getPcwlShopEnvById(Long id) {
		return baseMapper.selectById(id);
	}

	/**
	 * 根据Id修改
	 */
	@Override
	public Integer updatePcwlShopEnvById(PcwlShopEnv bean) {
		return baseMapper.updateById(bean);
	}

	/**
	 * 根据Id删除
	 */
	@Override
	public Integer deletePcwlShopEnvById(Long id) {
		return baseMapper.deleteById(id);
	}
}
